package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Category;
import com.itheima.reggie.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    //分类列表
    @GetMapping("/category/findAll")
    public ResultInfo findList() {
       List<Category>categoryList= categoryService.findList();
        return ResultInfo.success(categoryList);
    }
    //增加分类
    @PostMapping("/category")
    public ResultInfo save(@RequestBody Category category) {
        categoryService.save(category);
        return ResultInfo.success(null);
    }
    //修改分类
    @PutMapping("/category")
    public ResultInfo update(@RequestBody Category category) {
        categoryService.update(category);
        return ResultInfo.success(null);
    }
    //删除分类
    @DeleteMapping("/category")
    public ResultInfo deleteById(  Long id ) {
        ResultInfo resultInfo= categoryService.deleteById(id);
        return resultInfo;
    }

    //根据type查询
    @GetMapping("/category/list")
    public ResultInfo findByType(Integer type) {
        List<Category> categoryList = categoryService.findByType(type);
        return ResultInfo.success(categoryList);
    }


}
